import { useState } from "react";

enum ToggleStatus {
  Close = "Close",
  Open = "Open",
  Toggle = "Toggle",
}
export type Toggle = (status?: ToggleStatus) => void;

const useToggle = (): { opened: boolean; toggle: Toggle } => {
  const [opened, setOpened] = useState(false);
  const toggle: Toggle = (status?: ToggleStatus) => {
    switch (status) {
      case ToggleStatus.Close:
        setOpened(false);
        break;
      case ToggleStatus.Open:
        setOpened(true);
        break;
      case ToggleStatus.Toggle:
      default:
        setOpened((isOpened) => !isOpened);
        break;
    }
  };

  return { opened, toggle };
};

export { ToggleStatus };
export default useToggle;
